import pymysql

f = open('D:\\workspace\\702\\yyt\\all.txt', 'r')

dataList = []

while 1:
    line = f.readline()
    if not line:
        break
    arr = line.split('----')
    data = {"mobile": arr[0].strip(), "loginPwd": arr[1].strip(), "walletAddr": arr[2].strip()}
    dataList.append(data)
f.close()

# print(dataList)

conn = pymysql.connect(host='39.104.14.106', user='my-all-in', passwd='abcd4321', db='my-all-in')
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)

if dataList:
    values = ''
    for data in dataList:
        mobile = data['mobile']
        loginPwd = data['loginPwd']
        walletAddr = data['walletAddr']
        values += '("' + mobile + '","' + loginPwd + '","' + walletAddr + '"),'

    values = values[0:len(values) - 1]
    # print(values)

    sql = "insert into t_zwy_account_source " \
          "(mobile, loginPwd, walletAddr) values " + values

    print(sql)

    cursor.execute(sql)
    conn.commit()

    cursor.close()
    conn.close()
